Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
		dock : 'top',
		height : 40,
		items : [{
					text : '返回',
					xtype : 'button',
					listeners : {
						click : function() {
							location.href = "sysMgr/sys_setting";
						}
					}
				}, '-', {
					text : '删除',
					xtype : 'button',
					listeners : {
						click : function() {
							var grid = Ext.getCmp("education_grid");
							var selectionModel = grid.getSelectionModel();
							var models = selectionModel.getSelection();
							var ids = [];
							for (var i = 0; i < models.length; i++) {
								ids[i] = models[i].get("Id");
							}
							Ext.Ajax.request({
								url : '/education/delete',
								type : 'POST',
								params : {
									ids : ids
								},
								callback : function(options, success, response) {
									if (success) {
										var result = Ext
												.decode(response.responseText);
										if (result.success) {
											Ext.getCmp("education_grid")
													.getStore().reload();
										} else {
											Ext.Msg.alert('错误', result.msg);
										}
									}
								}
							});
						}
					}
				}, {
					text : '刷新',
					xtype : 'button',
					listeners : {
						click : function() {
							Ext.getCmp("education_grid").getStore().reload();
						}
					}
				}, '-', {
					id: 'add_education_form',
					xtype : 'form',
					layout: 'hbox',
					items : [{
								xtype : 'label',
								margin: '5 5',
								text : '名称:'
							}, {
								xtype : 'textfield',
								allowBlank : false,
								emptyText: '名称',
								id : 'education_name'
							}]
				}, {
					xtype : 'button',
					text : '添加',
					listeners : {
						click : function() {
							if(!Ext.getCmp("add_education_form").isValid()){
								return;
							}
							var educationName  = Ext.getCmp("education_name");
							Ext.Ajax.request({
								url : '/education/add',
								params : {
									Name : educationName.getValue()
								},
								callback : function(options, success, response) {
									if (success) {
										var result = Ext
												.decode(response.responseText);

										if (result.success) {
											educationName.setValue('');
											educationName.clearInvalid();
											Ext.getCmp("education_grid")
													.getStore().reload();
										}
										else{
											Ext.Msg.alert("错误", result.msg);
										}
									}
								}
							})
						}
					}
				}]
	});
	var store = Ext.create('Ext.data.Store', {
				fields : ['Id', 'Name', 'Desp'],
				autoLoad : true,
				proxy : {
					type : 'ajax',
					url : '/education/all',
					reader : {
						type : 'json',
						root : 'data.rows'
					}
				}
			});
	var grid = Ext.create('Ext.grid.Panel', {
				id : 'education_grid',
				margin : '0 5 5 5',
				selType : 'checkboxmodel',
				store : store,
				columns : [{
							text : '序号',
							xtype : 'rownumberer',
							width : 40,
							sortable : false
						}, {
							text : '名称',
							dataIndex : 'Name',
							flex : 1
						}, {
							text : '详细',
							width : 60,
							renderer : function(v, meta, record) {
								return '<a href="education/detail/'
										+ record.get("Id") + '">详细</a>';
							}
						}]
			});

	var panel = Ext.create("Ext.panel.Panel", {
				title : '学历管理',
				border : false,
				bodyBorder : false,
				layout : 'fit',
				dockedItems : [toolbar],
				items : [grid]
			});
	Ext.create('Ext.Viewport', {
				layout : 'fit',
				style : 'background:none;background-color:white;',
				items : [panel]
			});
});